package ar.uade.edu.fain.ad.server.dao.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "PEDIDO")
@NamedQueries({ 
	@NamedQuery(name = "pedido.sinFacturar", query = 
			"	SELECT p " +
			"	FROM PedidoEntity p " + 
			//"	FETCH JOIN p.comandas" +
			"	WHERE p.factura is null "
			+ "		AND p.estadoPedido = false" +
			"		AND p.mesa.sector.salon.local.id = :localId"),
	@NamedQuery(name = "pedido.byEstadoBySalon", query = 
			"	SELECT p"
			+ "	FROM PedidoEntity p"
			+ "	WHERE p.estadoPedido = :estado"
			+ "		AND p.mesa.sector.salon.id = :salonId" )	
})
public class PedidoEntity {

	@Id
	@GeneratedValue
	private Long id;

	@ManyToOne
	@JoinColumn(name = "idMesa")
	private MesaEntity mesa;

	@ManyToOne
	@JoinColumn(name = "idMozo")
	private MozoEntity mozo;

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "idPedido")
	private List<ComandaEntity> comandas;

	@Column
	private Boolean estadoPedido;

	@ManyToOne
	@JoinColumn(name = "idFactura")
	private FacturaEntity factura;

	public PedidoEntity() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public MesaEntity getMesa() {
		return mesa;
	}

	public void setMesa(MesaEntity mesa) {
		this.mesa = mesa;
	}

	public MozoEntity getMozo() {
		return mozo;
	}

	public void setMozo(MozoEntity mozo) {
		this.mozo = mozo;
	}

	public List<ComandaEntity> getComandas() {
		return comandas;
	}

	public void setComandas(List<ComandaEntity> comandas) {
		this.comandas = comandas;
	}

	public Boolean getEstadoPedido() {
		return estadoPedido;
	}

	public void setEstadoPedido(Boolean estadoPedido) {
		this.estadoPedido = estadoPedido;
	}

	public FacturaEntity getFactura() {
		return factura;
	}

	public void setFactura(FacturaEntity factura) {
		this.factura = factura;
	}
}
